package cn.demomaster.quickui_sample.ui.activity.component;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;

import cn.demomaster.quickrouter.actionbar.ACTIONBAR_TYPE;
import cn.demomaster.quickui.annotation.ActivityPager;
import cn.demomaster.quickui.annotation.ResType;
import cn.demomaster.quickui_sample.R;
import cn.demomaster.quickui_sample.ui.activity.BaseActivity;
import cn.demomaster.quickui.util.GroundGlassUtil;
import cn.demomaster.quickui.view.colorpicker.ColorPicker;

@ActivityPager(name = "导航栏", preViewClass = TextView.class, resType = ResType.Resource)//,iconRes = R.drawable.ic_nav)
public class ActionBarActivity extends BaseActivity implements View.OnClickListener {

    //@BindView(R.id.btn_ac_01)
    Button btn_ac_01;
    //@BindView(R.id.btn_ac_02)
    Button btn_ac_02;
    //@BindView(R.id.btn_ac_03)
    Button btn_ac_03;
    //@BindView(R.id.btn_ac_04)
    Button btn_ac_04;
    //@BindView(R.id.btn_ac_05)
    Button btn_ac_05;
    ColorPicker cp_color;
    int backgroundColor = Color.BLUE;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_actionbar);
        getActionBarTool().getRightView().setVisibility(View.GONE);
        RadioGroup rg_action = findViewById(R.id.rg_action);
        rg_action.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId==R.id.rb_01) {
                ((RadioButton) findViewById(R.id.rb_01)).setText(ACTIONBAR_TYPE.NORMAL + "");
                getActionBarTool().setActionBarType(ACTIONBAR_TYPE.NORMAL);
            }else if (checkedId==R.id.rb_02) {
                    ((RadioButton) findViewById(checkedId)).setText(ACTIONBAR_TYPE.NO_ACTION_BAR+"");
                    getActionBarTool().setActionBarType(ACTIONBAR_TYPE.NO_ACTION_BAR);
            }else if (checkedId==R.id.rb_03) {
                    ((RadioButton) findViewById(checkedId)).setText(ACTIONBAR_TYPE.NO_ACTION_BAR_NO_STATUS+"");
                    getActionBarTool().setActionBarType(ACTIONBAR_TYPE.NO_ACTION_BAR_NO_STATUS);
            }else if (checkedId==R.id.rb_04) {
                    ((RadioButton) findViewById(checkedId)).setText(ACTIONBAR_TYPE.ACTION_STACK+"");
                    getActionBarTool().setActionBarType(ACTIONBAR_TYPE.ACTION_STACK);
            }else if (checkedId==R.id.rb_05) {
                    ((RadioButton) findViewById(checkedId)).setText(ACTIONBAR_TYPE.ACTION_STACK_NO_STATUS+"");
                    getActionBarTool().setActionBarType(ACTIONBAR_TYPE.ACTION_STACK_NO_STATUS);
            }else if (checkedId==R.id.rb_07) {
                    ((RadioButton) findViewById(checkedId)).setText(ACTIONBAR_TYPE.NO_STATUS+"");
                    getActionBarTool().setActionBarType(ACTIONBAR_TYPE.NO_STATUS);
            }
        });

        cp_color = findViewById(R.id.cp_color);
        cp_color.setOnSelectChangeListener(new ColorPicker.OnSelectChangeListener() {
            @Override
            public void onSelectChange(int color) {
                backgroundColor = color;
                getActionBarTool().getActionBarLayout().getActionBarView().setBackgroundColor(color);
            }
        });

        SeekBar sb_color = findViewById(R.id.sb_color);
        sb_color.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                int red = (backgroundColor >> 16) & 0xFF;
                int green = (backgroundColor >> 8) & 0xFF;
                int blue = backgroundColor & 0xFF;

                String colorString = String.format("#%02X%02X%02X%02X", (int)(progress/100f * 255),red, green, blue);//去除了透明度
                System.out.println(colorString);
                int max = Color.parseColor(colorString);
                getActionBarTool().getActionBarLayout().getActionBarView().setBackgroundColor(max);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        getActionBarTool().getActionBarLayout().getActionBarView().setBackgroundColor(backgroundColor);


        btn_ac_01 = findViewById(R.id.btn_ac_01);
        btn_ac_02 = findViewById(R.id.btn_ac_02);
        btn_ac_03 = findViewById(R.id.btn_ac_03);
        btn_ac_04 = findViewById(R.id.btn_ac_04);
        btn_ac_05 = findViewById(R.id.btn_ac_05);

        btn_ac_01.setOnClickListener(this);
        btn_ac_02.setOnClickListener(this);
        btn_ac_03.setOnClickListener(this);
        btn_ac_04.setOnClickListener(this);
        btn_ac_05.setOnClickListener(this);

        CheckBox cb_use_background = findViewById(R.id.cb_use_background);
        cb_use_background.setOnCheckedChangeListener((buttonView, isChecked) -> {
           // getActionBarTool().setHasContainBackground(isChecked);
        });
        //getActionBarTool().getActionBarTip().setActionBarState();
        setTitle("导航栏");
        glassUtil = new GroundGlassUtil(mContext);
        glassUtil.setTargetView(rg_action);
        glassUtil.setParentView(findViewById(R.id.scrollView));
    }
    GroundGlassUtil glassUtil;
    @Override
    public void onClick(View v) {
     if (v.getId()==R.id.btn_ac_01) {
         getActionBarTool().setActionBarType(ACTIONBAR_TYPE.NORMAL);
     }else if (v.getId()==R.id.btn_ac_02) {
                getActionBarTool().setActionBarType(ACTIONBAR_TYPE.NO_ACTION_BAR);
     }else if (v.getId()==R.id.btn_ac_03) {
                getActionBarTool().setActionBarType(ACTIONBAR_TYPE.ACTION_STACK);
     }else if (v.getId()==R.id.btn_ac_04) {
                getActionBarTool().setActionBarType(ACTIONBAR_TYPE.ACTION_STACK_NO_STATUS);
     }else if (v.getId()==R.id.btn_ac_05) {
                getActionBarTool().setActionBarType(ACTIONBAR_TYPE.NO_ACTION_BAR_NO_STATUS);
     }
    }

    @Override
    public void finish() {
        glassUtil.onRelease(null);
        super.finish();
    }
}
